layui.use(['jquery','layer','table','form','laydate'],function(){
    var $=layui.jquery;
    var layer=layui.layer;
    var table=layui.table;
    var form=layui.form;
    var laydate=layui.laydate;

    laydate.render({
        elem: '#applyDate',
        type: 'datetime',
        trigger: 'click'
    })

    //刷新
    refresh = function refresh(){
        location.reload();
    }
    //返回
    $('#goBack').click(function () {
        parent.tabParentChange(3);
    })
    $(document).click(function () {
        parent.$('.rightMenu').hide();
    });

    $('.layui-row').children('.layui-btn').click(function () {
        $(this).removeClass('layui-btn-primary').siblings().addClass('layui-btn-primary');
    });

    //点击不同的按钮展示不同的用户
    //已通过
    $('#reviewed').click(function(){
        $.ajax({
            url:"/applyRecord/getApplyRecordByResult",
            data:{'result' : 2},
            type:"post",
            dataType:"json",
            success:function (data) {
                demoTable(data.data);
            }
        })
    })
    //已驳回
    $('#rejected').click(function(){
        $.ajax({
            url:"/applyRecord/getApplyRecordByResult",
            data:{'result' : 3},
            type:"post",
            dataType:"json",
            success:function (data) {
                demoTable(data.data);
            }
        })
    })

    getTable('','','');

    function getTable(applyDate,account,nickname){
        var param={
            'applyDate':applyDate,
            'account':account,
            'nickname':nickname
        }
        $.ajax({
            url:"/applyRecord/getApplicationProcessedList",
            data:param,
            type:"post",
            dataType:"json",
            success:function (data) {
                demoTable(data.data);
            }
        })
    }

    search = function search(){
        var applyDate=$("input[name=applyDate]").val();
        var account=$("input[name=account]").val();
        var nickname=$("input[name=nickname]").val();
        getTable(applyDate,account,nickname);
    }

    function demoTable(data){
        table.render({
            elem:'#demoTable',
            title:"委托书",
            data:data,
            toolbar:'#button_ids',
            limit:10,
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[10,20,30],
                first:"首页",
                last:"尾页",
            },
            cols:[[
                {type:'checkbox'},
                {title: '序号',align:'center', templet: function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:"nickname",title:"用户姓名",align:'center'},
                {field:"account",title:"用户账号",align:'center'},
                {field:"roleName",title:"申请职位",align:'center'},
                {field:"phone",title:"电话",align:'center'},
                {field:"applyDate",title:"申请时间",align:'center'},
                {field:"email",title:"邮箱",align:'center'},
                {field:"result",title:"申请状态",align:'center',templet:function(data){
                        if(data.result == 1){
                            return "待审核"
                        }else if(data.result == 2){
                            return "审核通过"
                        }else if(data.result == 3){
                            return "审核驳回"
                        }
                    }},
                {field:'',title:"操作",align:'center',toolbar:'#button_caozuo'}
            ]]
        })
    }

    //查看
    table.on('tool(demoTable)',function (obj) {
        var event = obj.event;
        if (event == "selectTable"){
            layer.open({
                type:2,
                title:"查看",
                area:["95%","99%"],
                scrollbar: false,
                offset:'auto',
                btn:["确定","取消"],
                content:"/user/creatorManage/creatorApplication/creator-application-select.html",
                success:function(layero,index){
                    var child = layero.find('iframe').contents();
                    child.find("#account").text(obj.data.account);
                    child.find("#nickname").text(obj.data.nickname);
                    child.find("#phone").text(obj.data.phone);
                    child.find("#idCard").text(obj.data.idCard);
                    child.find("#email").text(obj.data.email);
                    child.find("#consumption").text(obj.data.consumption);
                    child.find("#birthDate").text(obj.data.birthDate);
                    child.find("#freestyle").text(obj.data.freestyle);
                    child.find("#studyDate").text(obj.data.studyDate);
                    child.find("#intention").text(obj.data.intention);
                    child.find("#avatarUrl").attr("src",obj.data.avatarUrl);
                },
                end:function (layero, index) {
                    layer.close(index);
                }
            })
        }
    })
})